<template>
    <view>
        <div style="background-color: white;">
            <div v-if="adListRow1.length">
                <u-swiper :list="adListRow1" name="thumbnailUrl" duration="1000" :height="400"
                          img-mode="scaleToFill" :autoplay="true" :circular="false"
                          @click="clickItem"></u-swiper>
            </div>

            <div v-if="adListRow2.length">
                <u-swiper :list="adListRow2" name="thumbnailUrl" duration="1000" :height="400"
                          img-mode="scaleToFill" :autoplay="true" :circular="false"
                          @click="clickItem"></u-swiper>
            </div>
        </div>
    </view>
</template>

<script>

    import {TbAdService} from "../../../../dev/services/tb-ad.service";

    export default {
        props: ["storeAdTemplateId"],
        data() {
            return {
                adListRow1: [],
                adListRow2: [],
            }
        },
        mounted() {
            const _self = this;
            console.log(_self.storeAdTemplateId);
            _self.findAdListByStoreAdTemplateId();
        },
        methods: {
            clickItem(index) {
                const _self = this;
                console.log(index);
                new TbAdService().navByType(_self, _self.tbAdList[index]);
            },
            findAdListByStoreAdTemplateId() {
                const _self = this;
                new TbAdService().findTbAdListCascade({
                    fkId: _self.storeAdTemplateId,
                    status: "1",
                    deleted: 0,
                    isFindValidTimeRange: true
                }).then(result => {
                    let adList = result;
                    if (adList.length <= 5) {
                        _self.adListRow1 = adList;
                    } else if (adList.length <= 10) {
                        _self.adListRow1 = adList.filter((item, index) => index < 5);
                        _self.adListRow2 = adList.filter((item, index) => index >= 5);
                    } else {
                        _self.adListRow1 = adList.filter((item, index) => index < Math.ceil(adList.length / 2));
                        _self.adListRow2 = adList.filter((item, index) => index >= Math.ceil(adList.length / 2));
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
